package com.spring2mysql;


import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TeacherTest {
	

	//不能这样拿
/*	@Autowired
	private TeacherService teacherService;*/
	
	/**
	 * 通过springaop加载
	 * @throws Exception
	 */
	@Test
	public void testName() throws Exception {
		
		@SuppressWarnings("resource")
		ClassPathXmlApplicationContext ioc=new ClassPathXmlApplicationContext("com/spring2mysql/applicationContext.xml");
		
		TeacherEntity entity=new TeacherEntity();
		entity.setTeacherAge(88);
		entity.setTeacherName("liuhao");
		
		Object object = ioc.getBean("teacherService");
		
		TeacherService service=(TeacherService)object;
		
		service.insert(entity);
		
	
		
	}
	
	@Test
	public void findAll() throws Exception {
		
		@SuppressWarnings("resource")
		ClassPathXmlApplicationContext ioc=new ClassPathXmlApplicationContext("com/spring2mysql/applicationContext.xml");
		
		
		
		Object object = ioc.getBean("teacherService");
		
		TeacherService service=(TeacherService)object;
		
		service.fingAll();
		
		
		
	}

}
